<script setup lang="ts">
import { ref } from 'vue'

const list = ref([
  { id: 1, name: '《红楼梦》', author: '曹雪芹' },
  { id: 2, name: '《西游记》', author: '吴承恩' },
  { id: 3, name: '《水浒传》', author: '施耐庵' },
  { id: 4, name: '《三国演义》', author: '罗贯中' }
])

const delBook = (id: number) => {
  list.value = list.value.filter(item => item.id !== id)
}
</script>


<template>
  <div id="app">
    <h3>小黑的书架</h3>
    <ul>
      <li v-for="book in list" :key="book.id">
        <span>{{ book.name }}</span>
        <span>{{ book.author }}</span>
        <button @click="delBook(book.id)">删除</button>
      </li>
    </ul>
  </div>
</template>

<style></style>